package com.khstudio.videocapture;

import android.app.Activity;
import android.app.FragmentManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Environment;

import com.khstudio.api.util.KhLog;
import com.khstudio.videocapture.khduallist.KhDualListFragment;
import com.khstudio.videocapture.khduallist.KhDualListFragment.onKhDualListFragmentListener;

public class KhDualListActivity extends Activity {
    private KhDualListFragment  mKhDualListFragment;
    private SharedPreferences   mPrefs;
    private Context             mContext;
//    mCurrentPath = prefs.getString("CurrentPath", Environment.getExternalStorageDirectory().getAbsolutePath());
//    mStoragePath = prefs.getString("RepositoryPath", Environment.getExternalStorageDirectory().getAbsolutePath()+"/KVideoCapture/");

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        KhLog.i("onCreate");

        setContentView(R.layout.kh_activity_khduallist);
        mContext = this;

        mPrefs = getSharedPreferences("KhVideoCapture", MODE_PRIVATE);
        String path = mPrefs.getString("DualListPath", Environment.getExternalStorageDirectory().getPath());

        FragmentManager fm = getFragmentManager();
        mKhDualListFragment = (KhDualListFragment)fm.findFragmentById(R.id.kh_duallist_fragment);
        mKhDualListFragment.setPath(path);
        mKhDualListFragment.setonKhDualListFragmentListener(new onKhDualListFragmentListener() {

            @Override
            public void onFolderChange(String path) {
                KhLog.i("onFolderChange = %s", path);
                SharedPreferences.Editor editor = mPrefs.edit();
                editor.putString("DualListPath", path);
                editor.commit();
            }

            @Override
            public void onFileClick(String path) {
                KhLog.i("onFileClick = %s", path);

                Intent intent = new Intent(mContext, KhVideoCaptureActivity.class);
                intent.putExtra("path", path);
                startActivity(intent);

//                Intent intent = new Intent();
//                intent.setDataAndType(data, type)
//                intent.setDataAndNormalize(data)
            }
        });
    }

//    @Override
//    public boolean onCreateOptionsMenu(Menu menu) {
//        // Inflate the menu; this adds items to the action bar if it is present.
//        getMenuInflater().inflate(R.menu.main, menu);
//        return true;
//    }

    @Override
    public void onBackPressed() {
        mKhDualListFragment.back();
    }

}
